import 'dart:convert';
import 'package:http/http.dart';
import 'package:vdrag_saas/config.dart';

class HttpUserAction {
  HttpUserAction() {}

  static getIP() async {
    Response response =
        await get(Uri.parse('https://api.ipify.org/?format=json'));
    if (response.statusCode == 200) {
      print('请求成功');
      Map data = jsonDecode(response.body);
      return data['ip'];
    } else {
      print('请求失败');
      print('错误码：${response.statusCode}');
      return 'IP获取失败';
    }
  }

  static void recordUserAction(
      String name, String user_id, String appName) async {
    var url = Uri.parse(HttpConfig.userActionUrl + '/api/userAction');
    var response = await post(url,
        body: {'name': name, 'user_id': user_id, 'appName': appName});

    if (response.statusCode == 200) {
      print('请求成功');
      print('响应内容：${response.body}');
    } else {
      print('请求失败');
      print('错误码：${response.statusCode}');
    }
  }
}
